<template>
  <div>
    <!-- 输入手机号，调起手机号键盘 -->
    <van-field v-model="form.fareName" label="账号"/>
    <!-- 输入密码 -->
    <van-field v-model="form.farePassword" type="password" label="密码"/>
    <van-button  @click="loging" class="denglu111">登录</van-button>
    <van-button  @click="zhuce" class="zhuce111">注册</van-button>
  </div>
</template>
<script>
import {getUser} from "@/api/user/user";

export default {
  data() {
    return {
      form: {
        //用户名
        fareName: '',
        //用户密码
        farePassword: ''
      }
    }
  },
  created() {

  },
  methods: {
    loging() {
      //判断用户名和密码是否相等
      if (this.form.fareName == '' || this.form.farePassword == '') {
        this.$toast('账号或密码不能为空')
      } else {
        getUser(this.form).then(res => {
          this.$toast('登录成功')
          if (res.id != null) {
            window.localStorage.setItem('userId', res.id)
            // this.$router.push('/personalHome')
            this.$router.push({path: '/', query: {id: this.id}})

          } else {
            this.$toast('账号或密码错误')
          }
        })
      }
    },
    //注册
    zhuce(){
      this.$router.push({path: '/zhuce'})
    }
  }
}
</script>


<style>
.zhuce111{
  margin-top: 5px;
  margin-left: 10px;
  background-color:  red;
  color: white;
}
.denglu111{
  margin-top: 5px;
  margin-left: 10px;
  background-color:  red;
  color: white;
}
</style>